﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace F2S.LINQ2LinkedIn
{
    public class QueryStringBuilder
    {
        private string _path = "";
        private List<Tuple<string, string>> _parameters = new List<Tuple<string, string>>();

        public QueryStringBuilder(string path)
        {
            _path = path;
        }

        public void addQueryParameter(string key, string value)
        {
            _parameters.Add(new Tuple<string, string>(key, value));
        }

        public void addQueryParameter(string key, int value)
        {
            _parameters.Add(new Tuple<string, string>(key, value.ToString().ToLower()));
        }

        public void addQueryParameter(string key, bool value)
        {
            _parameters.Add(new Tuple<string, string>(key, value.ToString()));
        }

        public Uri Uri
        {
            get
            {
                var builder = new UriBuilder(_path);

                var qs = new StringBuilder();
                foreach (var p in _parameters)
                {
                    if (qs.Length > 0) qs.Append("&");
                    qs.Append(string.Format("{0}={1}", p.Item1, p.Item2));
                }

                builder.Query = qs.ToString();
                return builder.Uri;
            }
        }
    }
}
